package com.wcy.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcy.entity.User;
import com.wcy.entity.UserFeedback;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.user.FeignUserFeedbackService;
import com.wcy.util.JwtTokenUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class UserFeedbackController {
    @Resource
    private FeignUserFeedbackService feignUserFeedbackService;

    @GetMapping("userFeedback/page")
    public ResponseEntity<PageData<UserFeedback>> getPage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
                                                      @RequestParam(name = "pageSize",defaultValue = "10") int pageSize)
    {
        return ResponseEntity.ok(new PageData<>(UserFeedback.class, Objects.requireNonNull(feignUserFeedbackService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("userFeedback/add", "userFeedback/update", "userFeedback/delete"), ColumnConstructor.create()));
    }
    @GetMapping("userFeedback/list")
    public ResponseEntity<List<UserFeedback> > getList()
    {
        return feignUserFeedbackService.getList();
    }
    @PostMapping("userFeedback/add")
    public ResponseEntity<Void> add(@RequestBody UserFeedback userFeedback)
    {
        return feignUserFeedbackService.add(userFeedback);
    }
    @PutMapping("userFeedback/update")
    public ResponseEntity<Void> update(@RequestBody UserFeedback userFeedback)
    {
        return feignUserFeedbackService.update(userFeedback);
    }
    @DeleteMapping("userFeedback/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable("id") Integer id)
    {
        return feignUserFeedbackService.delete(id);
    }

    @GetMapping("userFeedback/user/page")
    public ResponseEntity<PageData<UserFeedback>> getUserPage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
                                                              @RequestParam(name = "pageSize",defaultValue = "10") int pageSize)
    {
        return ResponseEntity.ok(new PageData<>(UserFeedback.class, Objects.requireNonNull(feignUserFeedbackService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("", "", "userFeedback/user/delete"), ColumnConstructor.create()).setAlias("移除反馈",""));
    }

    @PutMapping("userFeedback/user/update")
    public ResponseEntity<Void> updateByUser(@RequestBody UserFeedback userFeedback)
    {
        return feignUserFeedbackService.update(userFeedback);
    }

    @DeleteMapping("userFeedback/user/delete/{id}")
    public ResponseEntity<Void> deleteByUser(@PathVariable("id") Integer id)
    {
        return feignUserFeedbackService.delete(id);
    }

    @PostMapping("userFeedback/user/add")
    public ResponseEntity<Boolean> addUserFeedback(@RequestBody UserFeedback userFeedback)
    {
        return feignUserFeedbackService.addUserFeedback(userFeedback);
    }
}
